package com.yichat.micro.msghttpservice.common.result;

import com.yichat.micro.msghttpservice.common.util.JsonUtil;
import com.yichat.micro.msghttpservice.common.util.StringUtil;
import lombok.Data;
import lombok.NoArgsConstructor;
import okhttp3.Response;

import java.util.HashMap;

/**
 * Created by chenmohan on 2019/04/08
 *
 * @description
 */
@Data
@NoArgsConstructor
public class RpcResult extends HttpResult {

    public static HashMap<String, String> respMap(HttpResult httpResult) {
        HashMap<String, String> resultMap = new HashMap<>();
        resultMap.put("code", httpResult.code + "");
        resultMap.put("msg", httpResult.msg);
        resultMap.put("id", httpResult.id + "");
        if (httpResult.data != null && httpResult.data instanceof String && StringUtil.isNotEmpty((String) httpResult.data)) {
            resultMap.put("data", JsonUtil.toJSON(httpResult.data));
        }
        if (StringUtil.isNotEmpty(httpResult.buz)) {
            resultMap.put("buz", httpResult.buz);
        }
        return resultMap;
    }

    public RpcResult(int code, String msg, String data, String buz, Long id) {
        super(code, msg, data, buz, id);
    }
}
